﻿<environment include="Development">
    <script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
    <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
</environment>
<environment exclude="Development">
    <script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.17.0/jquery.validate.min.js"
            asp-fallback-src="~/lib/jquery-validation/dist/jquery.validate.min.js"
            asp-fallback-test="window.jQuery && window.jQuery.validator"
            crossorigin="anonymous"
            integrity="sha384-rZfj/ogBloos6wzLGpPkkOr/gpkBNLZ6b6yLy4o+ok+t/SAKlL5mvXLr0OXNi1Hp">
    </script>
    <script src="https://ajax.aspnetcdn.com/ajax/jquery.validation.unobtrusive/3.2.9/jquery.validate.unobtrusive.min.js"
            asp-fallback-src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
            asp-fallback-test="window.jQuery && window.jQuery.validator && window.jQuery.validator.unobtrusive"
            crossorigin="anonymous"
            integrity="sha384-ifv0TYDWxBHzvAk2Z0n8R434FL1Rlv/Av18DXE43N/1rvHyOG4izKst0f2iSLdds">
    </script>
</environment>

<script>
    function ajaxAntiForgery(url, params, index) {
        layer.close(index);
        index = layer.load(1, {
            shade: [0.1, '#fff'] //0.1透明度的白色背景
        });
        //获取防伪标记
        var token = $('@Html.AntiForgeryToken()').val();
        //params["__RequestVerificationToken"] = token;
        $.ajax({
            type: "POST",
            data: params,
            cache: false,
            async: false,
            url: url,
            headers:
            {
                "RequestVerificationToken": token//$('#RequestVerificationToken').val()
            },
            success: function (msg) {
                if (msg.success == true) {
                    layer.msg('操作成功!', { icon: 1, time: 1000 });

                    var form = $('form.ajaxTable');

                    if (form.length > 0) {
                        var d = {};
                        var t = form.serializeArray();
                        $.each(t, function () {
                            d[this.name] = this.value;
                        });

                        layui.table.reload(form.data("target"),
                            {
                                page: {
                                    curr: 1 //重新从第 1 页开始
                                },
                                where: d
                            });
                    } else {
                        $('a.btn-success i.Hui-iconfont').click();
                    }
                } else if (msg.success == false) {
                    layer.msg('操作失败!', { icon: 2, time: 1000 });

                    console.error(msg.errorMsg);
                }

            },
            error: function (msg) {
                layer.msg('服务器错误!', { icon: 5, time: 1000 });
            }
        });
        layer.close(index);
    }
</script>